
#include "tp2.h"

bgr_t  colores[] = { {  0,   0,   0},
                     { 64,  64,  64},
                     {128, 128, 128},
                     {192, 192, 192},
                     {255, 255, 255} };

void bandas_c (
	unsigned char *src,
	unsigned char *dst,
	int m,
	int n,
	int src_row_size,
	int dst_row_size
)
{
	unsigned char (*src_matrix)[src_row_size] = (unsigned char (*)[src_row_size]) src;
	unsigned char (*dst_matrix)[dst_row_size] = (unsigned char (*)[dst_row_size]) dst;

	unsigned int sumaComponentes;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			bgr_t *p_dest = (bgr_t*)&dst_matrix[i][j*4];
			bgr_t *p_source = (bgr_t*)&src_matrix[i][j*4];
			sumaComponentes = p_source->b + p_source->r + p_source->g;

			if (sumaComponentes < 96)
			{
				*p_dest = colores[0];
			}
			else if (sumaComponentes < 288)
			{
				*p_dest = colores[1];
			}
			else if (sumaComponentes < 480)
			{
				*p_dest = colores[2];
			}
			else if (sumaComponentes < 672)
			{
				*p_dest = colores[3];
			}
			else
			{
				*p_dest = colores[4];
			}
		}
	}
}
